package au.com.handsunited.model;

import java.util.HashSet;
import java.util.Set;

import org.hibernate.search.annotations.Indexed;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import au.com.handsunited.model.relationship.Relationship;
import au.com.handsunited.model.skill.Skill;

/**
 * @author arunda
 *
 */
@Indexed
public class Group extends BaseEntity {


	private static Logger logger = LoggerFactory.getLogger(Group.class);

	/**
	 *
	 */
	public Group() {
		super();
	}


	/**
	 * @see au.com.handsunited.model.BaseEntity#isGroup()
	 */
	@Override
	public boolean isGroup() {
		return true;
	}


	/**
	 * @see au.com.handsunited.model.BaseEntity#getEntityType()
	 */
	@Override
	public String getEntityType() {
		return "group";
	}


	/**
	 * A <code>Group</code>'s available skills is the sum total of the skills
	 * of its members.
	 *
	 * @return the skills that this group has available
	 */
	public Set<Skill> getAvailableSkills() {

		Set<Skill> availableSkills = new HashSet<Skill>();

		/*
		 * Get any skills that the group has
		 */
		availableSkills.addAll(getSkills());

		/*
		 * Get the skills of the user members
		 */
		for (Relationship relationship : getUserRelationships()) {
			User user = (User)relationship.getRelative();

			availableSkills.addAll(user.getSkills());
		}

		return availableSkills;
	}


}
